from django.core.paginator import Paginator
from django.shortcuts import render
from django.views import View

from organization.forms import SchooolOrgForm
from organization.models import CourseOrg

from django import http

# 由于开发进度不统一，
# 为了能运行，以下是临时代码
from utils import constants


class OrgView(View):
    """
    学校视图
    """

    def get(self, request):
        """
        返回学校页面
        :param request:
        :return:
        """
        # 获取课程查询集
        courses = CourseOrg.objects.all().order_by('fav_nums')
        hot_orgs = courses[0:2]
        # 获取当前页
        pageNum = request.GET.get('page', 1)
        # 定义分页器
        # 创建分页器：每页N条记录
        paginator = Paginator(courses, constants.COURSE_LIST_LIMIT)
        # 获取每页商品数据
        try:
            all_orgs = paginator.page(pageNum)
        except:
            # 如果page_num不正确，默认给用户404
            return http.HttpResponseNotFound('empty page')
        all_orgs.pages = [i for i in range(1, paginator.num_pages + 1)]
        return render(request, 'org-list.html', {'all_orgs': all_orgs, 'hot_orgs': hot_orgs})


class Org_View(View):
    def get(self,request,pk):
        return render(request, 'org-detail-homepage.html')
class Org_Course(View):
    pass
class Org_Desc(View):
    pass
class Org_Teacher(View):
    pass
class Org_Add(View):
    pass
class Course(View):
    """
    临时视图
    """
    pass
